<%@page import="com.yang.dao.UserDao"%>
<%@page import="com.yang.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>admin page</title>
	<link rel="stylesheet" href="css/bootstrap.css" />
	<script type="text/javascript" src="js/jquery.js"></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>
<body>
	<div class="navbar navbar-fixed-top navbar-inverse">
		<div class="navbar-inner">
		<a class="brand" href="#">project</a>
		<ul class="nav">
		<li class="active"><a href="#">服务</a></li>
		<li><a href="tolist.jspx?father=0">文件下载列表</a></li>
		</ul>
		    <ul class="nav pull-right">
		 	   <li class="dropdown">
		    	<a href="#" class="dropdown-toggle" data-toggle="dropdown">
		   			 管理
		  			 <b class="caret"></b>
		   	 </a>
		    	<ul class="dropdown-menu">
					<li><a href="exit.jspx">退出</a></li>
					<c:if test="${user.power==8 }">
						<li class="divider"></li>
						<li><a href="deleteAllDate.jspx">清理数据库</a></li>
					</c:if>
		    </ul>
		   	 </li>
		   	 </ul>
		</div>
	</div>
	<div style="margin-top:100px;width:100px;" class="tabs navbar-fixed-top">
	hello, ${user.name }!<br>
	<%
		if ("start".equals(request.getParameter("state"))) {
	%>
	<a href="#" class="btn btn-success btn-large disabled">开启服务</a>
	<%
		} else {
	%>
	<a href="start.jspx" class="btn btn-success btn-large">开启服务</a>
	<%
		}
	%>
	<br />
	<%
		if ("restart".equals(request.getParameter("state"))) {
	%>
	<a href="#" class="btn btn-warning btn-large disabled">重启服务</a>
	<%
		} else {
	%>
	<a href="restart.jspx" class="btn btn-warning btn-large">重启服务</a>
	<%
		}
	%>
	<br />
	<%
		if ("stop".equals(request.getParameter("state"))) {
	%>
	<a href="#" class="btn btn-danger btn-large disabled">停止服务</a>
	<%
		} else {
	%>
	<a href="stop.jspx" class="btn btn-danger btn-large">停止服务</a>
	<%
		}
	%>
	</div>
	<div style="margin-top:100px;margin-left:100px;">
		<c:if test="${user.power==8 or user.power==4}">
			<%
			UserDao ud=new UserDao();
			List<User> list=ud.findList();
			if(list.size()>0){
				request.setAttribute("list",list);
			}
			 %>
			 <table class="table" >
				<tr>
					<th>编号</th>
					<th>用户名</th>
					<th>删除</th>
					<th>身份</th>
				</tr>
					<c:forEach var="u" items="${list }" varStatus="status">
					<c:if test="${u.name != user.name and u.power<user.power}">
						<tr>
							<td>${u.id}</td>
							<td>${u.name }</td>
							<td>
								<a href="#" onclick="del(${u.id })" id="${u.id }">删除</a>
								<c:if test="${user.power==8  and u.power==1}">|<a href="#" onclick="addmin(${u.id })" id="${u.id }">添加为管理员</a></c:if>
							</td>
							<td>
							<c:if test="${u.power==4 }">管理员</c:if>
							<c:if test="${u.power==2 }">已删除用户</c:if>
							<c:if test="${u.power==1 }">普通用户</c:if>
							</td>
						</tr>
					</c:if>
				</c:forEach>
				<tr>
					<td>
					<script type="text/javascript">
						function del(id){
							$.post("deluser.jspx", { id: id},
							   function(data){
							   		if(data=='ok'){
							   		$("#"+id).parent().parent().remove();
							   		}else{
								     alert("删除失败！");
							   		}
							   });
						}
						function addmin(id){
							$.post("addmin.jspx", { id: id},
							   function(data){
							   window.location="login-success.jsp";
							   })
						}
						</script>
					</td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</table>
		</c:if>
	</div>
</body>
</html>
